﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ComputerArchitecture.Core.Logging;
using ComputerArchitecture.Numbers;
using ComputerArchitecture.Units.Integers.Signed.Implementations;
using ComputerArchitecture.Units.Integers.Unsigned.Implementations;

namespace ComputerArchitecture.Units.Integers
{
    public static class NumberConversion
    {
        public static UnsignedBitNumber ToOffseted(this ISignedBitNumber number, ISignedBitNumber offset)
        {
            
            bool overflow;
            ILoggingService log = new NLogFacadeLoggingService();
            log.DisableLogging();
            var result = new SignedAdderUnit(log).Add(number, offset, out overflow);
            log.EnableLogging();
            return new UnsignedBitNumber(result);
            
            
        }

        public static SignedBitNumber ToComplement(this IUnsignedBitNumber number, IUnsignedBitNumber offset)
        {
            /*
            bool overflow;
            ILoggingService log = new NLogFacadeLoggingService();
            log.DisableLogging();
            var result = new UnsignedSubstractUnit(log).Substract(number, offset, out overflow);
            log.EnableLogging();
            return new SignedBitNumber(result);
            */
            bool overflow;
            ISignedBitNumber v = new SignedBitNumber(number), o = new SignedBitNumber(offset);
            ILoggingService log = new NLogFacadeLoggingService();
            log.DisableLogging();
            var result = new SignedSubstractUnit(log).Substract(v, o, out overflow);
            log.EnableLogging();
            return new SignedBitNumber(result);
        }
    }
}
